package com.fyzk.activity.lottery.zc.tz_dialog;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.lottery.jc.football.JCInfo;
import com.tyjc.lottery.R;

public abstract class ZC_Dialog_BaseActivity extends AlertDialog {

    //顶部
    private TextView zhu, ke;
    //中部
    protected LinearLayout center_ll;
    //底部
    private TextView cancel, sure;
    protected JCInfo infor;

    protected Context context;

//    private int position;

    protected ZC_Dialog_BaseActivity(Context context,JCInfo infos) {
        super(context);
        this.context = context;
        this.infor = infos;
        View view = View.inflate(context,R.layout.zc_dialog,null);
        info(view);
        setView(view);
    }
    protected ZC_Dialog_BaseActivity(Context context) {
        super(context);
    }

//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.zc_dialog);
//        if (Build.VERSION.SDK_INT >= 11) {
//            setFinishOnTouchOutside(false);
//        } else {
//
//        }
//
//        info();
//        init();
//    }

    /**
     * 计算 从投注区返回结果
     *
     * @param infor
     * @return
     */
    protected String getResult(JCInfo infor) {
        String str = "";
        int clickNum = 0;
        for (int i = 0; i < infor.getTouZhuInfor().size(); i++) {
            if (infor.getTouZhuInfor().get(i).isSelect()) {
                str += infor.getTouZhuInfor().get(i).getBiFen() + ",";
                clickNum++;
            }
        }
        infor.setOnclikNum(clickNum);
        if (!str.equals("")) {
            str = str.substring(0, str.length() - 1);
        }
        return str;
    }


    protected abstract void init();

    protected abstract JCInfo getResult();

    private void info(View view) {

        //顶部
        zhu = (TextView)view. findViewById(R.id.zcbf_dialog_zhu);
        ke = (TextView) view.findViewById(R.id.zcbf_dialog_ke);
        //中间
        center_ll = (LinearLayout) view.findViewById(R.id.zc_dlg_center);
        //底部
        cancel = (TextView) view.findViewById(R.id.zcbf_dialog_btm_cancel);
        sure = (TextView)view. findViewById(R.id.zcbf_dialog_btm_sure);
        //事件
        zhu.setText(infor.getHomeTeam());
        ke.setText(infor.getAwayTeam());

        cancel.setOnClickListener(new ZCBF_DLG_onClick());
        sure.setOnClickListener(new ZCBF_DLG_onClick());

    }

//    /**
//     * 返回
//     */
//    protected void back() {
//        Intent intent = new Intent();
//        JCInfo infor = getResult();
//        intent.putExtra("bf", position);
//        setResult(0, intent);
//        ZC_Dialog_BaseActivity.this.finish();
//    }

    public void sureClick(){}

    /**
     * 单击事件
     *
     * @author Administrator
     */
    class ZCBF_DLG_onClick implements  View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.zcbf_dialog_btm_cancel:
                    ZC_Dialog_BaseActivity.this.cancel();
//                    ZC_Dialog_BaseActivity.this.finish();
                    break;
                case R.id.zcbf_dialog_btm_sure:
                    sureClick();
                    ZC_Dialog_BaseActivity.this.cancel();
                    break;
                default:
                    break;
            }
        }
    }
}
